// import { for } from "core-js/fn/symbol";
import chartConfig from "./chartConfig";

// 维保单位前五 / 困人率
const getMaintainUnit = (arrs) => {
  if (arrs == {} || arrs == null || arrs == undefined) {
    console.log("arr传空");
    arrs = {
      types: ["A单位", "B单位", "B1单位", "VV单位", "F单位"],
      data: [1, 3, 2, 4, 6],
    };
  }

  let unitOption = {
    grid: {
      top: "5%",
      left: "16%",
      right: "10%",
    },
    tooltip: {
      trigger: "item",
      formatter: "{b}: {c}",
    },
    xAxis: {
      type: "value",
      name: "单位总数",
      nameTextStyle: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size,
        align: "right",
        verticalAlign: "top",
        padding: [3, 0, 0, 0],
      },
      axisLabel: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size,
        margin: 25,
      },
      minInterval: 1,
    },
    yAxis: {
      type: "category",
      data: arrs.types,
      axisLabel: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size + 4,
        interval: 0,
        // rotate: 30,
        shadowOffsetY: 5,
        formatter: function (value, index) {
            return 'NO.'+ (index + 1)
        }
      },
    },
    series: [
      {
        data: arrs.data,
        type: "bar",
        itemStyle: {
          normal: {
            color: function(params) {
              var colorlist = chartConfig.c_color_arr_6;
              return colorlist[params.dataIndex];
            },
            barBorderRadius: [0, 5, 5, 0],
          },
        },
        barCategoryGap: "50%",
        label: {
          show: true,
          formatter: function(data) {
            // console.log(data);
            if (data.name == "使用单位" && data.value > 0) {
              return data.value + " " + arrs.count;
            }
            return data.value;
          },
        },
      },
    ],
  };
  return unitOption;
};

// 人员持证比例
const getMaintainPerson = (arrs) => {
  if (arrs == {} || arrs == null || arrs == undefined) {
    console.log("arr传空");
    arrs = {
      types: ["有证", "无证"],
      data: [
        { value: 12, name: "有证" },
        { value: 2, name: "无证" },
      ],
    };
  }
  let ret = []
  for (let i = 0; i < arrs.types.length; i++) {
    const ele = arrs.types[i];
    ret[i] = {name:ele, value:arrs.data[i]}
  }
  arrs.data = ret

  let deviceStatus = {
    color: chartConfig.c_color_arr_6,
    tooltip: {
      trigger: "item",
      formatter: "{b}: {c} ({d}%)",
    },
    legend: {
      orient: "vertical",
      right: 10,
      data: arrs.types,
      textStyle: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size,
      },
    },
    series: [
      {
        type: "pie",
        radius: ["20%", "80%"],
        avoidLabelOverlap: false,
        label: {
          show: true,
          position: "outside",
          fontSize: chartConfig.c_font_size,
          formatter: "{b}: {c}",
          color: chartConfig.c_font_color,
        },
        emphasis: {
          label: {
            show: true,
            fontSize: chartConfig.c_font_size + 2,
            fontWeight: "bold",
          },
        },
        labelLine: {
          show: false,
        },
        data: arrs.data,
      },
    ],
  };
  return deviceStatus;
};

// 维保人员年龄
const getMaintainAge = (arrs) => {
  if (arrs == {} || arrs == null || arrs == undefined) {
    console.log("arr传空");
    arrs = {
      types: ["20-30", "30-40", "40-50"],
      data: [3, 6, 4,],
    };
  }

  let personAge = {
    grid: {
      left: "3%",
      right: "5%",
      bottom: "3%",
      containLabel: true,
    },
    xAxis: {
      type: "category",
      data: arrs.types,
      axisLabel: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size + 2,
        rotate: 30,
        
      },
    },
    yAxis: {
      type: "value",
      name: "人数",
      nameTextStyle: {
        color: chartConfig.c_font_color,
      },
      axisLabel: {
        color: chartConfig.c_font_color,
        fontSize: chartConfig.c_font_size + 2,
      },
    },
    series: [
      {
        data: arrs.data,
        type: "bar",
        showBackground: true,
        backgroundStyle: {
          color: "rgba(220, 220, 220, 0.2)",
        },
        label: {
          show: true,
          formatter: "{c}人",
          fontSize: chartConfig.c_font_size + 2,
        },
        itemStyle: {
          normal: {
            color: function(params) {
              var colorlist = chartConfig.c_color_arr_3;
              return colorlist[params.dataIndex];
            },
            barBorderRadius: [5, 5, 0, 0],
          },
        },
      },
    ],
  };
  return personAge;
};

// 本月维保次数统计
const getMaintainMonth = (arrs) => {

    if (arrs == {} || arrs == null || arrs == undefined) {
      console.log("arr传空");
      arrs = {
        types: [
          "-",
          "-",
          "-",
          "-",
          "-",
          "-",
        ],
        data: [1,7,14,21,28,31]
      };
    }
    
    let yearTrend = {
      tooltip: {
        trigger: "axis",
      },
      // legend: {
      //   data: ["锅炉", "压力容器", "电梯", "起重机械", "气瓶", "游乐设施"],
      //   textStyle: {
      //     color: chartConfig.c_font_color,
      //     fontSize: 14,
      //   },
      // },
      grid: {
        left: "3%",
        right: "5%",
        bottom: "3%",
        containLabel: true,
      },
      xAxis: {
        type: "category",
        boundaryGap: false,
        data: arrs.types,
        axisLabel: {
          color: chartConfig.c_font_color,
          fontSize: chartConfig.c_font_size,
        },
      },
      yAxis: {
        type: "value",
        axisLabel: {
          color: chartConfig.c_font_color,
          fontSize: chartConfig.c_font_size + 2,
        },
      },
      series: 
        {
          name: "设备数量",
          type: "line",
          stack: "总量",
          data: arrs.data,
        },
      
    };
    return yearTrend;
  };

export { 
    getMaintainUnit, 
    getMaintainPerson,
    getMaintainAge,
    getMaintainMonth,
};
